<?php

/**
* ShowRouteFormModule.class.php
*
* Concrete page module responsable for creating slide show list
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("framework/PageModule.class.php");
require_once("MDB2.php");
require_once("HTML/QuickForm.php");
require_once("HTML/QuickForm/Renderer/Default.php");


// {{{ SlideShowListModule

class ShowRouteFormModule extends PageModule 
{
    // {{{ Class operations 

    // {{{ SlideShowListModule
    /**
    * C'tor
    */
    
    function ShowRouteFormModule()
    {
        trigger_error("ENTER ShowRouteFormModule::ShowRouteFormModule()", E_USER_NOTICE);
    }
    // }}}
    // {{{ getContent

    /**
    * Function returns page content
    *
    */

    function getContent()
    {

        trigger_error("ENTER ShowRouteFormModule::getContent()", E_USER_NOTICE);
        $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES'); 
 
        $tpl = new HTML_Template_IT($options["templates_dir"]);
        $tpl->loadTemplatefile("route.tpl.xhtml",true,true);
        
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN'); 
        $dbh = new PDO($options['dsn_string']);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $sth = $dbh->prepare("SELECT * FROM guide WHERE rowid = :id");
        $sth->bindParam(':id',$_GET['id']);
        $sth->execute();
        $guideRow = $sth->fetch(PDO::FETCH_ASSOC);

        $globalOpt = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $uploadOpt = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD');

        $tpl->setVariable("NAME",$guideRow['name']);        

        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        if ( $guideRow['pic_file'] )
        {
            
            $tpl->setCurrentBlock('image_row');
            $tpl->setVariable("ALT",$guideRow['pic_file']);
            $tpl->setVariable("URL",$global['service_url'].'send_image.php?id='.$guideRow['pic_file']);
            $tpl->parseCurrentBlock();
        }

        if ( $guideRow['desc'] )
        {
            $tpl->setCurrentBlock('desc_row');
            $tpl->setVariable("DESC",$guideRow['desc']);
            $tpl->parseCurrentBlock();

        }

        if ( $guideRow['sound_file'] )
        {
            $tpl->setCurrentBlock('sound_row');
            $tpl->setVariable("URL",$global['service_url'].'send_sound.php?id='.$guideRow['sound_file']);
            $tpl->parseCurrentBlock();
        }

        $sth = $dbh->prepare("SELECT rowid,* FROM slide WHERE guide_id = :id ORDER BY `order` ASC");
        $sth->bindParam(':id',$_GET['id']);
        $sth->execute();

        while ( $row = $sth->fetch(PDO::FETCH_ASSOC) )
        {
            $tpl->setCurrentBlock('slide_row');
            $tpl->setVariable("SLIDE_NAME",$row['name']);
            $tpl->setVariable("URL",(isset($options['service_url']) ? $options['service_url'] : null)."index.php?cmd=ShowSlide&id=".$row['rowid']."&guide_id=".$row['guide_id']);
            $tpl->parseCurrentBlock();
        }
        
        return $tpl->get();
    }
    
    // }}}

    // }}}
}

// }}} 

?>
